﻿
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using gfLibrary;
using DBUtility;
using Model;
using BLL;

namespace GreatGF
{
    public partial class DEV_INFO_Insert_Update : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                string strMode = Request["m"];

                if((strMode == "u")||(strMode == "b")||(strMode == "r"))
                {
                    string strId = Request["UniqueKey"];

                    DEV_INFO_BLL m_DEV_INFO_BLL = new DEV_INFO_BLL();

                    if(m_DEV_INFO_BLL.Exists(Convert.ToInt32(strId)) == true)
                    {
                        DEV_INFO m_DEV_INFO = new DEV_INFO();
                        m_DEV_INFO = m_DEV_INFO_BLL.GetModel(Convert.ToInt32(strId));

                        txtID.Text = m_DEV_INFO.ID.ToString();
                        txtJCXH.Text = m_DEV_INFO.JCXH.ToString();
                        txtSBMC.Text = m_DEV_INFO.SBMC;
                        txtSBXH.Text = m_DEV_INFO.SBXH;
                        txtSBZZC.Text = m_DEV_INFO.SBZZC;
                        txtSBRZBH.Text = m_DEV_INFO.SBRZBH;
                        txtCGJXH.Text = m_DEV_INFO.CGJXH;
                        txtCGJSCC.Text = m_DEV_INFO.CGJSCC;
                        txtCGJCCBH.Text = m_DEV_INFO.CGJCCBH;
                        txtCGJRZBH.Text = m_DEV_INFO.CGJRZBH;
                        txtFQYXH.Text = m_DEV_INFO.FQYXH;
                        txtFQYSCC.Text = m_DEV_INFO.FQYSCC;
                        txtFQYCCBH.Text = m_DEV_INFO.FQYCCBH;
                        txtFQYRZBH.Text = m_DEV_INFO.FQYRZBH;
                        txtLLJXH.Text = m_DEV_INFO.LLJXH;
                        txtLLJSCC.Text = m_DEV_INFO.LLJSCC;
                        txtLLJCCBH.Text = m_DEV_INFO.LLJCCBH;
                        txtLLJRZBH.Text = m_DEV_INFO.LLJRZBH;
                        txtYDJ_BTG_XH.Text = m_DEV_INFO.YDJ_BTG_XH;
                        txtYDJ_BTG_SCC.Text = m_DEV_INFO.YDJ_BTG_SCC;
                        txtYDJ_BTG_CCBH.Text = m_DEV_INFO.YDJ_BTG_CCBH;
                        txtYDJ_BTG_RZBH.Text = m_DEV_INFO.YDJ_BTG_RZBH;
                        txtYDJ_LZ_XH.Text = m_DEV_INFO.YDJ_LZ_XH;
                        txtYDJ_LZ_SCC.Text = m_DEV_INFO.YDJ_LZ_SCC;
                        txtYDJ_LZ_CCBH.Text = m_DEV_INFO.YDJ_LZ_CCBH;
                        txtYDJ_LZ_RZBH.Text = m_DEV_INFO.YDJ_LZ_RZBH;
                    }
                    else
                    {
                        gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                        gfAjaxJs.SetGoToUrl(this.UpdatePanel1, "DEV_INFO_List.aspx");
                    }

                    if((strMode == "b")||(strMode == "r"))
                    {
                        txtID.ReadOnly = true;
                        txtID.CssClass = "csstextboxreadonly";
                        txtJCXH.ReadOnly = true;
                        txtJCXH.CssClass = "csstextboxreadonly";
                        txtSBMC.ReadOnly = true;
                        txtSBMC.CssClass = "csstextboxreadonly";
                        txtSBXH.ReadOnly = true;
                        txtSBXH.CssClass = "csstextboxreadonly";
                        txtSBZZC.ReadOnly = true;
                        txtSBZZC.CssClass = "csstextboxreadonly";
                        txtSBRZBH.ReadOnly = true;
                        txtSBRZBH.CssClass = "csstextboxreadonly";
                        txtCGJXH.ReadOnly = true;
                        txtCGJXH.CssClass = "csstextboxreadonly";
                        txtCGJSCC.ReadOnly = true;
                        txtCGJSCC.CssClass = "csstextboxreadonly";
                        txtCGJCCBH.ReadOnly = true;
                        txtCGJCCBH.CssClass = "csstextboxreadonly";
                        txtCGJRZBH.ReadOnly = true;
                        txtCGJRZBH.CssClass = "csstextboxreadonly";
                        txtFQYXH.ReadOnly = true;
                        txtFQYXH.CssClass = "csstextboxreadonly";
                        txtFQYSCC.ReadOnly = true;
                        txtFQYSCC.CssClass = "csstextboxreadonly";
                        txtFQYCCBH.ReadOnly = true;
                        txtFQYCCBH.CssClass = "csstextboxreadonly";
                        txtFQYRZBH.ReadOnly = true;
                        txtFQYRZBH.CssClass = "csstextboxreadonly";
                        txtLLJXH.ReadOnly = true;
                        txtLLJXH.CssClass = "csstextboxreadonly";
                        txtLLJSCC.ReadOnly = true;
                        txtLLJSCC.CssClass = "csstextboxreadonly";
                        txtLLJCCBH.ReadOnly = true;
                        txtLLJCCBH.CssClass = "csstextboxreadonly";
                        txtLLJRZBH.ReadOnly = true;
                        txtLLJRZBH.CssClass = "csstextboxreadonly";
                        txtYDJ_BTG_XH.ReadOnly = true;
                        txtYDJ_BTG_XH.CssClass = "csstextboxreadonly";
                        txtYDJ_BTG_SCC.ReadOnly = true;
                        txtYDJ_BTG_SCC.CssClass = "csstextboxreadonly";
                        txtYDJ_BTG_CCBH.ReadOnly = true;
                        txtYDJ_BTG_CCBH.CssClass = "csstextboxreadonly";
                        txtYDJ_BTG_RZBH.ReadOnly = true;
                        txtYDJ_BTG_RZBH.CssClass = "csstextboxreadonly";
                        txtYDJ_LZ_XH.ReadOnly = true;
                        txtYDJ_LZ_XH.CssClass = "csstextboxreadonly";
                        txtYDJ_LZ_SCC.ReadOnly = true;
                        txtYDJ_LZ_SCC.CssClass = "csstextboxreadonly";
                        txtYDJ_LZ_CCBH.ReadOnly = true;
                        txtYDJ_LZ_CCBH.CssClass = "csstextboxreadonly";
                        txtYDJ_LZ_RZBH.ReadOnly = true;
                        txtYDJ_LZ_RZBH.CssClass = "csstextboxreadonly";
                        btnSave.Visible = false;
                    }

                    if(strMode == "r")
                    {
                        btnBack.Visible = false;
                    }
                }
                if (strMode == "i")
                {
                    lblOperateType.Text = "添加";
                }
                if (strMode == "b" || strMode == "r")
                {
                    lblOperateType.Text = "查看";
                }
                if (strMode == "u")
                {
                    lblOperateType.Text = "修改";
                }
            }

            btnBack.Attributes["onclick"] = "javascript:window.location.href='DEV_INFO_List.aspx';return false;";
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            string strID = txtID.Text.Trim();
            string strJCXH = txtJCXH.Text.Trim();
            string strSBMC = txtSBMC.Text.Trim();
            string strSBXH = txtSBXH.Text.Trim();
            string strSBZZC = txtSBZZC.Text.Trim();
            string strSBRZBH = txtSBRZBH.Text.Trim();
            string strCGJXH = txtCGJXH.Text.Trim();
            string strCGJSCC = txtCGJSCC.Text.Trim();
            string strCGJCCBH = txtCGJCCBH.Text.Trim();
            string strCGJRZBH = txtCGJRZBH.Text.Trim();
            string strFQYXH = txtFQYXH.Text.Trim();
            string strFQYSCC = txtFQYSCC.Text.Trim();
            string strFQYCCBH = txtFQYCCBH.Text.Trim();
            string strFQYRZBH = txtFQYRZBH.Text.Trim();
            string strLLJXH = txtLLJXH.Text.Trim();
            string strLLJSCC = txtLLJSCC.Text.Trim();
            string strLLJCCBH = txtLLJCCBH.Text.Trim();
            string strLLJRZBH = txtLLJRZBH.Text.Trim();
            string strYDJ_BTG_XH = txtYDJ_BTG_XH.Text.Trim();
            string strYDJ_BTG_SCC = txtYDJ_BTG_SCC.Text.Trim();
            string strYDJ_BTG_CCBH = txtYDJ_BTG_CCBH.Text.Trim();
            string strYDJ_BTG_RZBH = txtYDJ_BTG_RZBH.Text.Trim();
            string strYDJ_LZ_XH = txtYDJ_LZ_XH.Text.Trim();
            string strYDJ_LZ_SCC = txtYDJ_LZ_SCC.Text.Trim();
            string strYDJ_LZ_CCBH = txtYDJ_LZ_CCBH.Text.Trim();
            string strYDJ_LZ_RZBH = txtYDJ_LZ_RZBH.Text.Trim();

            if (gfValidate.Is_Integer(strJCXH) == false)
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "[JCXH]不是有效的数字格式。");
                return;
            }

            DEV_INFO m_DEV_INFO = new DEV_INFO();
            DEV_INFO_BLL m_DEV_INFO_BLL = new DEV_INFO_BLL();

            m_DEV_INFO.JCXH = Convert.ToInt32(strJCXH);
            m_DEV_INFO.SBMC = strSBMC;
            m_DEV_INFO.SBXH = strSBXH;
            m_DEV_INFO.SBZZC = strSBZZC;
            m_DEV_INFO.SBRZBH = strSBRZBH;
            m_DEV_INFO.CGJXH = strCGJXH;
            m_DEV_INFO.CGJSCC = strCGJSCC;
            m_DEV_INFO.CGJCCBH = strCGJCCBH;
            m_DEV_INFO.CGJRZBH = strCGJRZBH;
            m_DEV_INFO.FQYXH = strFQYXH;
            m_DEV_INFO.FQYSCC = strFQYSCC;
            m_DEV_INFO.FQYCCBH = strFQYCCBH;
            m_DEV_INFO.FQYRZBH = strFQYRZBH;
            m_DEV_INFO.LLJXH = strLLJXH;
            m_DEV_INFO.LLJSCC = strLLJSCC;
            m_DEV_INFO.LLJCCBH = strLLJCCBH;
            m_DEV_INFO.LLJRZBH = strLLJRZBH;
            m_DEV_INFO.YDJ_BTG_XH = strYDJ_BTG_XH;
            m_DEV_INFO.YDJ_BTG_SCC = strYDJ_BTG_SCC;
            m_DEV_INFO.YDJ_BTG_CCBH = strYDJ_BTG_CCBH;
            m_DEV_INFO.YDJ_BTG_RZBH = strYDJ_BTG_RZBH;
            m_DEV_INFO.YDJ_LZ_XH = strYDJ_LZ_XH;
            m_DEV_INFO.YDJ_LZ_SCC = strYDJ_LZ_SCC;
            m_DEV_INFO.YDJ_LZ_CCBH = strYDJ_LZ_CCBH;
            m_DEV_INFO.YDJ_LZ_RZBH = strYDJ_LZ_RZBH;

            if (string.IsNullOrEmpty(strID) == true)
            {
                strID = "-1";
            }

            if (m_DEV_INFO_BLL.Exists(Convert.ToInt32(strID)) == false)
            {
                m_DEV_INFO.ID = m_DEV_INFO_BLL.GetMax_ID();

                if (m_DEV_INFO_BLL.Insert(m_DEV_INFO) == true)
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增成功！");
                    txtID.Text = m_DEV_INFO.ID.ToString();
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "新增失败！");
                }
            }
            else
            {
                if (m_DEV_INFO_BLL.Update(m_DEV_INFO, Convert.ToInt32(strID)) == true)
                {
                     gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新成功！");
                }
                else
                {
                    gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "更新失败！");
                }
            }
        }
    }
}
